package com.pid.common.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class DateTransUtils {

    public static void main(String[] args) {
        String str = "Mon Dec 13 00:00:00 CST 2021";
        Date date = Myparse(str, "EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
//        String end_time = Myformat(date, "yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        //获取date类型的class
        //        System.out.println(date.getClass().toString());
        date.setHours(date.getHours()+23);
        date.setMinutes(date.getMinutes()+59);
        date.setSeconds(date.getSeconds()+59);
//        System.out.println(Myformat(date,"yyyy-MM-dd HH:mm:ss",Locale.CHINA));
    }

//解析指定格式的字符串​，返回Date
    public static Date Myparse(String str, String pattern, Locale locale) {
        if (str == null || pattern == null) {
            return null;
        }
        try {
            return (Date) new SimpleDateFormat(pattern, locale).parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

//格式化指定类型的date​，返回String
    public static String Myformat(Date date, String pattern, Locale locale) {
        if (date == null || pattern == null) {
            return null;
        }
        return new SimpleDateFormat(pattern, locale).format(date);
    }
}
